/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.zqkey.rescuecommand;

import java.util.ArrayList;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.zqkey.rescuecommand.entity.Level;

public class Assets {
	public static Texture start;
	public static TextureRegion startRegion;
	public static Texture background;
	public static TextureRegion backgroundRegion;
	
	public static Texture buttonNew;
	public static Texture buttonContinue;
	public static Texture buttonHelp;
	public static Texture buttonAbout;
	
	public static Texture cabinet;
	public static Texture commandAnticlockwise;
	public static Texture commandClockwise;
	public static Texture commandForward;
	public static Texture commandFun1;
	public static Texture commandFun2;
	public static Texture commandJump;
	public static Texture commandKey;
	
	public static Texture musicImg;
	
	public static Texture ground;
	
//	public static Texture player;
//	public static Texture playerBullet;

	public static Music music;
//	public static Sound backgroundSound;
	
	public static ArrayList<Level> levels;
	
	public static Texture loadTexture (String file) {
		return new Texture(Gdx.files.internal(file));
	}

	public static void load () {
		start = loadTexture("image/start.jpg");
		startRegion = new TextureRegion(start, 0, 0, Settings.gameWidth, Settings.gameHeight);
		background = loadTexture("image/background.jpg");
		backgroundRegion = new TextureRegion(background, 0, 0, Settings.gameWidth, Settings.gameHeight);
		
		buttonNew = loadTexture("image/button_new.png");
		buttonContinue = loadTexture("image/button_continue.png");
		buttonHelp = loadTexture("image/button_help.png");
		buttonAbout = loadTexture("image/button_about.png");
		
		cabinet = loadTexture("image/cabinet.jpg");
		commandAnticlockwise = loadTexture("image/command_anticlockwise.jpg");
		commandClockwise = loadTexture("image/command_clockwise.jpg");
		commandForward = loadTexture("image/command_forward.jpg");
		commandFun1 = loadTexture("image/command_fun1.jpg");
		commandFun2 = loadTexture("image/command_fun2.jpg");
		commandJump = loadTexture("image/command_jump.jpg");
		commandKey = loadTexture("image/command_key.jpg");
		
		musicImg = loadTexture("image/music.png");
		
		ground = loadTexture("image/ground.png");
//		player = loadTexture("data/player.png");
		
		music = Gdx.audio.newMusic(Gdx.files.internal("music/background.mp3"));
		music.setLooping(true);
		music.setVolume(0.5f);
//		backgroundSound = Gdx.audio.newSound(Gdx.files.internal("sound/background.mp3"));
		
		// instance level
		levels = new ArrayList<Level>();
		FileHandle levelDir = Gdx.files.internal("level");
		if(levelDir.isDirectory()) {
			FileHandle[] fs = levelDir.list();
			for(FileHandle f : fs) {
				String fileName = f.name();
				if(fileName.endsWith(".rc")) {
					Level l = new Level(f);
					levels.add(l);
				}
			}
			System.out.println();
		}
	}

	public static void playSound (Sound sound) {
		if (Settings.soundEnabled)
			sound.play(1);
	}
	
	public static void playMusic(Music music) {
		if (Settings.soundEnabled)
			music.play();
	}
	
	public static void pauseMusic(Music music) {
		if (music.isPlaying()) {
			music.pause();
		}
	}
}
